package educar.abmMateria;

import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Marce
 */
public class MateriaView extends javax.swing.JFrame {

// <editor-fold defaultstate="collapsed" desc="Constructor">
    public MateriaView() {
        initComponents();
    }
    // </editor-fold>
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbAgregar = new javax.swing.JButton();
        jbEliminar = new javax.swing.JButton();
        jbBuscar = new javax.swing.JButton();
        jScrollPane = new javax.swing.JScrollPane();
        jtMateria = new javax.swing.JTable();
        jlTitulo = new javax.swing.JLabel();
        jtfCriterio = new javax.swing.JTextField();
        jlCriterio = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jbAgregar.setText("Agregar");

        jbEliminar.setText("Eliminar");

        jbBuscar.setText("Buscar");

        jtMateria.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "Codigo Materia", "Nombre de Materia", "DNI del Docente"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane.setViewportView(jtMateria);
        jtMateria.getColumnModel().getColumn(0).setResizable(false);
        jtMateria.getColumnModel().getColumn(0).setPreferredWidth(15);

        jlTitulo.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlTitulo.setText("Administracion de Materia");

        jlCriterio.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jlCriterio.setText("DNI del Docente ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlCriterio, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCriterio, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(102, 102, 102))
            .addComponent(jlTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jlTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jlCriterio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfCriterio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
 
//<editor-fold defaultstate="collapsed" desc=" Declaracion de Variables ">
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JButton jbAgregar;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbEliminar;
    private javax.swing.JLabel jlCriterio;
    private javax.swing.JLabel jlTitulo;
    private javax.swing.JTable jtMateria;
    private javax.swing.JTextField jtfCriterio;
    // End of variables declaration//GEN-END:variables
//</editor-fold>

    
    public JTable getJTMateria(){
        return this.jtMateria;
    }

    public DefaultTableModel getModeloTabla(){
        return (DefaultTableModel) jtMateria.getModel();
    }
    
    public void setModeloTabla(DefaultTableModel tabla){
        if (tabla == null){ 
            jtMateria.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "Codigo materia", "Nombre", "Dni"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });       
        } else {
            this.jtMateria.setModel(tabla);
        }    
        jtMateria.getTableHeader().setReorderingAllowed(false);
        jScrollPane.setViewportView(jtMateria);
        jtMateria.getColumnModel().getColumn(0).setResizable(false);
        jtMateria.getColumnModel().getColumn(0).setPreferredWidth(50);
        jtMateria.getColumnModel().getColumn(1).setPreferredWidth(160);
        jtMateria.getColumnModel().getColumn(2).setPreferredWidth(160);
        jtMateria.getColumnModel().getColumn(3).setPreferredWidth(160);
    }
    
    public JButton getJbAgregar() {
        return jbAgregar;
    }

    public JButton getJbBuscar() {
        return jbBuscar;
    }

    public JButton getJbEliminar() {
        return jbEliminar;
    }

    public String getCriterio() {
        return jtfCriterio.getText();
    }

    public void setActionListener(MateriaController listener) {
        jbAgregar.addActionListener(listener);
        jbEliminar.addActionListener(listener);
        jbBuscar.addActionListener(listener);
    }

    public void setMouseListener(MateriaController listener) {
        jtMateria.addMouseListener(listener);
    }

    public void setWindowListener(MateriaController listener){
        this.addWindowListener(listener);
    }
    
}
